import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.security.*;
import java.security.cert.Certificate;

/**
 * User: Administrator
 * Date: 2017/5/17
 * Time: 0:07
 */
public class ReadPrivateKeyFromKeyStore {
public static void main(String[] args) throws Exception{
    FileInputStream is = new FileInputStream("G:\\cert\\test.keystore");

    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(is, "123456".toCharArray());

    String alias = "ep00001";

    Key key = keystore.getKey(alias, "123456".toCharArray());
    if (key instanceof PrivateKey) {
        System.out.println(new BASE64Encoder().encode(key.getEncoded()));
    }
}
}
